﻿using System;
using System.Xml;

namespace YArchitech.HCLoad.XmlData
{
	public class RoomLoad
	{
		public RoomLoad(RoomLoadCollect roomLoadCollect)
		{
			this.parent = roomLoadCollect;
		}

		public Room Room
		{
			get
			{
				if (this.parent == null)
				{
					return null;
				}
				return this.parent.Parent;
			}
		}

		public virtual RoomLoadCollect ParentRoomLoadCollect
		{
			get
			{
				return this.parent;
			}
			set
			{
				this.parent = value;
			}
		}

		public string LoadTypeStr
		{
			get
			{
				return this.sLoadType;
			}
			set
			{
				this.sLoadType = value;
			}
		}

		public virtual HcObjectType LoadType
		{
			get
			{
				if (string.IsNullOrEmpty(this.LoadTypeStr))
				{
					return (HcObjectType)Enum.ToObject(typeof(HcObjectType), this.WhType);
				}
				return HcObjectTypeName.ToType(this.LoadTypeStr);
			}
		}

		public int ID
		{
			get
			{
				return this.nID;
			}
			set
			{
				this.nID = value;
			}
		}

		public int WhType
		{
			get
			{
				return this.nWhType;
			}
			set
			{
				this.nWhType = value;
			}
		}

		public string Description
		{
			get
			{
				return this.sDescription;
			}
			set
			{
				this.sDescription = value;
			}
		}

		public string Name
		{
			get
			{
				return this.sName;
			}
			set
			{
				this.sName = value;
			}
		}

		public string GuidString
		{
			get
			{
				return this.sGuidString;
			}
			set
			{
				this.sGuidString = value;
			}
		}

		public double[] ZsLfhAll
		{
			get
			{
				if (this.aryZsLfhAll == null)
				{
					this.aryZsLfhAll = new double[24];
					int num = 0;
					while (num < this.ZsLfhQr.Length && num < this.ZsLfhXr.Length)
					{
						this.aryZsLfhAll[num] = this.ZsLfhXr[num] + this.ZsLfhQr[num];
						num++;
					}
				}
				return this.aryZsLfhAll;
			}
		}

		public double[] ZsLfhXr
		{
			get
			{
				return this.adZsLfhXr;
			}
			set
			{
				this.adZsLfhXr = value;
			}
		}

		public double[] ZsLfhQr
		{
			get
			{
				return this.adZsLfhQr;
			}
			set
			{
				this.adZsLfhQr = value;
			}
		}

		public double[] ZsSfh
		{
			get
			{
				return this.adZsSfh;
			}
			set
			{
				this.adZsSfh = value;
			}
		}

		public double[] ColdFsZd
		{
			get
			{
				return this.adColdFsZd;
			}
			set
			{
				this.adColdFsZd = value;
			}
		}

		public double[] ColdTc
		{
			get
			{
				return this.adColdTc;
			}
			set
			{
				this.adColdTc = value;
			}
		}

		public double[] ColdLoad
		{
			get
			{
				return this.adColdLoad;
			}
			set
			{
				this.adColdLoad = value;
			}
		}

		public double[] ColdXrLoad
		{
			get
			{
				return this.adColdXrLoad;
			}
			set
			{
				this.adColdXrLoad = value;
			}
		}

		public double[] ColdQrLoad
		{
			get
			{
				return this.adColdQrLoad;
			}
			set
			{
				this.adColdQrLoad = value;
			}
		}

		public double[] ColdsLoad
		{
			get
			{
				return this.adColdsLoad;
			}
			set
			{
				this.adColdsLoad = value;
			}
		}

		public double DjRfhXr
		{
			get
			{
				return this.dDjRfhXr;
			}
			set
			{
				this.dDjRfhXr = value;
			}
		}

		public double DjRfhQr
		{
			get
			{
				return this.dDjRfhQr;
			}
			set
			{
				this.dDjRfhQr = value;
			}
		}

		public double DjSfh
		{
			get
			{
				return this.dDjSfh;
			}
			set
			{
				this.dDjSfh = value;
			}
		}

		public double HeatQj
		{
			get
			{
				return this.dHeatQj;
			}
			set
			{
				this.dHeatQj = value;
			}
		}

		public double HeatQ1
		{
			get
			{
				return this.dHeatQ1;
			}
			set
			{
				this.dHeatQ1 = value;
			}
		}

		public double HeatV
		{
			get
			{
				return this.dHeatV;
			}
			set
			{
				this.dHeatV = value;
			}
		}

		public double HeatQ2
		{
			get
			{
				return this.dHeatQ2;
			}
			set
			{
				this.dHeatQ2 = value;
			}
		}

		public double HeatQ3
		{
			get
			{
				return this.dHeatQ3;
			}
			set
			{
				this.dHeatQ3 = value;
			}
		}

		public ChildCollect ChildCollect
		{
			get
			{
				return this.childCollect;
			}
		}

		public void AddChildCollect()
		{
			try
			{
				this.childCollect = new ChildCollect(this);
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
		}

		public int WhID
		{
			get
			{
				return this.m_nWhId;
			}
			set
			{
				this.m_nWhId = value;
			}
		}

		public WhTempl WhTempl
		{
			get
			{
				if (this.WhID < 0)
				{
					return null;
				}
				return this.ParentRoomLoadCollect.DataBase.WallDataTemplDict.GetWhTempl(this.WhID);
			}
		}

		public virtual bool DoPropExchange(XmlElement xe3, bool bLoad)
		{
			if (!bLoad)
			{
				return false;
			}
			this.ID = int.Parse(xe3.GetAttribute("ID"));
			this.LoadTypeStr = xe3.GetAttribute("LoadType");
			this.Name = xe3.GetAttribute("Name");
			this.Description = xe3.GetAttribute("Description");
			this.GuidString = xe3.GetAttribute("GuidString");
			this.ZsLfhXr = DataBase.StrToDblArr(xe3.GetAttribute("ZsLfhXr"));
			this.ZsLfhQr = DataBase.StrToDblArr(xe3.GetAttribute("ZsLfhQr"));
			this.ZsSfh = DataBase.StrToDblArr(xe3.GetAttribute("ZsSfh"));
			this.ColdFsZd = DataBase.StrToDblArr(xe3.GetAttribute("ColdFsZd"));
			this.ColdTc = DataBase.StrToDblArr(xe3.GetAttribute("ColdTc"));
			this.ColdLoad = DataBase.StrToDblArr(xe3.GetAttribute("ColdLoad"));
			this.ColdXrLoad = DataBase.StrToDblArr(xe3.GetAttribute("ColdXrLoad"));
			this.ColdQrLoad = DataBase.StrToDblArr(xe3.GetAttribute("ColdQrLoad"));
			this.ColdsLoad = DataBase.StrToDblArr(xe3.GetAttribute("ColdsLoad"));
			if (!string.IsNullOrEmpty(xe3.GetAttribute("WhType")))
			{
				this.WhType = int.Parse(xe3.GetAttribute("WhType"));
			}
			else
			{
				this.WhType = -1;
			}
			if (!string.IsNullOrEmpty(xe3.GetAttribute("WhID")))
			{
				this.WhID = int.Parse(xe3.GetAttribute("WhID"));
			}
			else
			{
				this.WhID = -1;
			}
			if (!string.IsNullOrEmpty(xe3.GetAttribute("DjRfhXr")))
			{
				this.DjRfhXr = RoomLoad.ToDouble(xe3.GetAttribute("DjRfhXr"));
			}
			if (!string.IsNullOrEmpty(xe3.GetAttribute("DjRfhQr")))
			{
				this.DjRfhQr = RoomLoad.ToDouble(xe3.GetAttribute("DjRfhQr"));
			}
			if (!string.IsNullOrEmpty(xe3.GetAttribute("DjSfh")))
			{
				this.DjSfh = RoomLoad.ToDouble(xe3.GetAttribute("DjSfh"));
			}
			if (!string.IsNullOrEmpty(xe3.GetAttribute("HeatQj")))
			{
				this.HeatQj = RoomLoad.ToDouble(xe3.GetAttribute("HeatQj"));
			}
			if (!string.IsNullOrEmpty(xe3.GetAttribute("HeatQ1")))
			{
				this.HeatQ1 = RoomLoad.ToDouble(xe3.GetAttribute("HeatQ1"));
			}
			if (!string.IsNullOrEmpty(xe3.GetAttribute("HeatV")))
			{
				this.HeatV = RoomLoad.ToDouble(xe3.GetAttribute("HeatV"));
			}
			if (!string.IsNullOrEmpty(xe3.GetAttribute("HeatQ2")))
			{
				this.HeatQ2 = RoomLoad.ToDouble(xe3.GetAttribute("HeatQ2"));
			}
			if (!string.IsNullOrEmpty(xe3.GetAttribute("HeatQ3")))
			{
				this.HeatQ3 = RoomLoad.ToDouble(xe3.GetAttribute("HeatQ3"));
			}
			XmlNode xmlNode = xe3.SelectSingleNode("ChildCollect");
			if (xmlNode != null)
			{
				XmlNodeList childNodes = xmlNode.ChildNodes;
				if (this.ChildCollect == null)
				{
					this.AddChildCollect();
				}
				foreach (object obj in childNodes)
				{
					XmlElement xe4 = (XmlElement)((XmlNode)obj);
					ChildWhJg childWhJg = new ChildWhJg(this.ChildCollect);
					childWhJg.DoPropExchange(xe4, bLoad);
					this.ChildCollect.LoadChildWhJg(childWhJg);
				}
			}
			if (HcObjectType.LO_FreshAir == this.LoadType)
			{
				this.DoPropExchange_FreshAir(xe3, bLoad);
			}
			return true;
		}

		public double[] XrLoad
		{
			get
			{
				return this.m_dXrLoad;
			}
		}

		public double[] QrLoad
		{
			get
			{
				return this.m_dQrLoad;
			}
		}

		public double[] Load
		{
			get
			{
				return this.m_dLoad;
			}
		}

		public double[] SLoad
		{
			get
			{
				return this.m_dSLoad;
			}
		}

		public double[] TakeonXrLoad
		{
			get
			{
				return this.m_dTakeonXrLoad;
			}
		}

		public double[] TakeonQrLoad
		{
			get
			{
				return this.m_dTakeonQrLoad;
			}
		}

		public double[] TakeonLoad
		{
			get
			{
				return this.m_dTakeonLoad;
			}
		}

		public double[] TakeonSLoad
		{
			get
			{
				return this.m_dTakeonSLoad;
			}
		}

		public double FreshAirG
		{
			get
			{
				return this.m_dFreshAirG;
			}
		}

		public bool IsCooling
		{
			get
			{
				return this.m_IsCooling;
			}
		}

		public double HeatXrLoad
		{
			get
			{
				return this.m_dHeatXrLoad;
			}
		}

		public double HeatQrLoad
		{
			get
			{
				return this.m_dHeatQrLoad;
			}
		}

		public double HeatLoad
		{
			get
			{
				return this.m_dHeatLoad;
			}
		}

		public double HeatsLoad
		{
			get
			{
				return this.m_dHeatsLoad;
			}
		}

		public double HeatTakeonXrLoad
		{
			get
			{
				return this.m_dHeatTakeonXrLoad;
			}
		}

		public double HeatTakeonQrLoad
		{
			get
			{
				return this.m_dHeatTakeonQrLoad;
			}
		}

		public double HeatTakeonLoad
		{
			get
			{
				return this.m_dHeatTakeonLoad;
			}
		}

		public double HeatTakeonsLoad
		{
			get
			{
				return this.m_dHeatTakeonsLoad;
			}
		}

		public double Qj
		{
			get
			{
				return this.HeatQj;
			}
		}

		public double Q1
		{
			get
			{
				return this.HeatQ1;
			}
		}

		public double V
		{
			get
			{
				return this.HeatV;
			}
		}

		public double Q2
		{
			get
			{
				return this.HeatQ2;
			}
		}

		public double Q3
		{
			get
			{
				return this.HeatQ3;
			}
		}

		public bool IsHjCr
		{
			get
			{
				return this.m_bIsHjCr;
			}
		}

		public double HjFh
		{
			get
			{
				return this.m_dHjFh;
			}
		}

		private static bool ToBool(string str)
		{
			return !string.IsNullOrEmpty(str) && str == "1";
		}

		protected static double ToDouble(string str)
		{
			if (string.IsNullOrEmpty(str))
			{
				return 0.0;
			}
			double result;
			try
			{
				result = Convert.ToDouble(str);
			}
			catch (Exception ex)
			{
				string message = ex.Message;
				result = 0.0;
			}
			return result;
		}

		protected static int ToInt(string str)
		{
			if (string.IsNullOrEmpty(str))
			{
				return 0;
			}
			int result;
			try
			{
				result = int.Parse(str);
			}
			catch (Exception ex)
			{
				string message = ex.Message;
				result = 0;
			}
			return result;
		}

		protected void DoPropExchange_FreshAir(XmlElement xe, bool bLoad)
		{
			if (!bLoad)
			{
				return;
			}
			this.m_dXrLoad = DataBase.StrToDblArr(xe.GetAttribute("ColdXrLoad"));
			this.m_dQrLoad = DataBase.StrToDblArr(xe.GetAttribute("ColdQrLoad"));
			this.m_dLoad = DataBase.StrToDblArr(xe.GetAttribute("ColdLoad"));
			this.m_dSLoad = DataBase.StrToDblArr(xe.GetAttribute("ColdsLoad"));
			this.m_dTakeonXrLoad = DataBase.StrToDblArr(xe.GetAttribute("ColdTakeonXrLoad"));
			this.m_dTakeonQrLoad = DataBase.StrToDblArr(xe.GetAttribute("ColdTakeonQrLoad"));
			this.m_dTakeonLoad = DataBase.StrToDblArr(xe.GetAttribute("ColdTakeonLoad"));
			this.m_dTakeonSLoad = DataBase.StrToDblArr(xe.GetAttribute("ColdTakeonsLoad"));
			this.m_dHeatXrLoad = RoomLoad.ToDouble(xe.GetAttribute("HeatXrLoad"));
			this.m_dHeatQrLoad = RoomLoad.ToDouble(xe.GetAttribute("HeatQrLoad"));
			this.m_dHeatLoad = RoomLoad.ToDouble(xe.GetAttribute("HeatLoad"));
			this.m_dHeatsLoad = RoomLoad.ToDouble(xe.GetAttribute("HeatsLoad"));
			this.m_dHeatTakeonXrLoad = RoomLoad.ToDouble(xe.GetAttribute("HeatTakeonXrLoad"));
			this.m_dHeatTakeonQrLoad = RoomLoad.ToDouble(xe.GetAttribute("HeatTakeonQrLoad"));
			this.m_dHeatTakeonLoad = RoomLoad.ToDouble(xe.GetAttribute("HeatTakeonLoad"));
			this.m_dHeatTakeonsLoad = RoomLoad.ToDouble(xe.GetAttribute("HeatTakeonsLoad"));
			this.m_bIsHjCr = RoomLoad.ToBool(xe.GetAttribute("IsHjCr"));
			this.m_dHjFh = RoomLoad.ToDouble(xe.GetAttribute("HeatHjFh"));
			this.m_dFreshAirG = double.Parse(xe.GetAttribute("FreshAirG"));
			this.m_IsCooling = ("0" == xe.GetAttribute("FreshLoadType"));
		}

		private RoomLoadCollect parent;

		private string sLoadType;

		private int nID;

		private int nWhType = -1;

		private string sDescription;

		private string sName;

		private string sGuidString;

		private double[] aryZsLfhAll;

		private double[] adZsLfhXr;

		private double[] adZsLfhQr;

		private double[] adZsSfh;

		private double[] adColdFsZd;

		private double[] adColdTc;

		private double[] adColdLoad;

		private double[] adColdXrLoad;

		private double[] adColdQrLoad;

		private double[] adColdsLoad;

		private double dDjRfhXr;

		private double dDjRfhQr;

		private double dDjSfh;

		private double dHeatQj;

		private double dHeatQ1;

		private double dHeatV;

		private double dHeatQ2;

		private double dHeatQ3;

		private ChildCollect childCollect;

		private int m_nWhId = -1;

		protected double[] m_dXrLoad;

		protected double[] m_dQrLoad;

		protected double[] m_dLoad;

		protected double[] m_dSLoad;

		protected double[] m_dTakeonXrLoad;

		private double[] m_dTakeonQrLoad;

		private double[] m_dTakeonLoad;

		private double[] m_dTakeonSLoad;

		private double m_dFreshAirG;

		private bool m_IsCooling;

		private double m_dHeatXrLoad;

		private double m_dHeatQrLoad;

		private double m_dHeatLoad;

		private double m_dHeatsLoad;

		private double m_dHeatTakeonXrLoad;

		private double m_dHeatTakeonQrLoad;

		private double m_dHeatTakeonLoad;

		private double m_dHeatTakeonsLoad;

		private bool m_bIsHjCr;

		private double m_dHjFh;
	}
}
